//index.js
//获取应用实例
const app = getApp()
import store from "../../utils/factory"
let that = null;
import {
  refundOrder,
  wxLogin,
} from "../../utils/config"

Page({
  data: {
    array1: ['不想要了', '商品未送到', '商品破损已拒签', '商品变质/有异物', '少发漏发', '发错货'],
    array2: ['不想要了', '未按时发货'],
    array: [],
    index: 0,
    remark: "",
    reason: "",
    detail: {},
    total: "",
    express: ""
  },
  onLoad: function (e) {
    that = this
  },
  onShow() {
    let refundOrderDetail = store.get("refundOrderDetail")
    console.log(refundOrderDetail)
    this.setData({
      detail: refundOrderDetail,
      express: store.get("express"),
      total: refundOrderDetail.total + store.get("express"),
      array: refundOrderDetail.status == "待发货" ? this.data.array2 : this.data.array1
    })
    console.log(this.data.array)
  },
  watchRemark(e) {
    this.setData({
      remark: e.detail.value
    })
  },
  bindPickerChange(e) {
    console.log(e.detail.value)
    this.setData({
      reason: this.data.array[e.detail.value]
    })
  },
  refundOrder() {
    refundOrder({
      id: this.data.detail.id,
      remark: this.data.remark,
      reason: this.data.reason
    }).then(res => {
      wx.showModal({
        title: "温馨提示",
        content: '申请退款成功',
        showCancel: false, //是否显示取消按钮
        success: function (res) {
          wx.navigateBack({ //返回上一页面或多级页面
            delta: 1
          })
        },
      })
    })
  }
})